import java.sql.* ;

class CustomerDetails
{



CreateConnection cc ;

// Indexding of field a/c to database........

int id ;  // index-1
String name ; // index-2
String addr1 ; // index-3
String addr2 ; // index-4
String addr3 ; // index-5

String city ;  //index-6
String state ;  // index-7
String country ;  // index-8
String pincode ; // index-9
String ph1 ; // index-10
String ph2 ; // index-11
String email ; // index-12



	CustomerDetails()
	{

				try{

				cc = new CreateConnection() ;

				}
				catch(Exception e)
				{}


	}






	CustomerDetails(String[] s)  // string s consists of all details of customer
	{


									id = Integer.parseInt(s[0]) ;
									name = s[1] ;
									addr1 = s[2] ;
									addr2 = s[3] ;
									addr3 = s[4] ;
									city = s[5] ;
									state = s[6] ;
									country = s[7] ;
									pincode = s[8] ;
									ph1 = s[9] ;
									ph2 = s[10] ;
									email = s[11] ;
							/*
									System.out.println(id);
							System.out.println(name);
							System.out.println(addr1);
							System.out.println(addr2);
							System.out.println(addr3);
							System.out.println(city);
							System.out.println(state);
							System.out.println(country);
							System.out.println(pincode);
							System.out.println(ph1);
							System.out.println(ph2);
							System.out.println(email);


							*/


								try{

									cc = new CreateConnection() ;

									}
									catch(Exception e)
								{}





	}




	void insertDetailsInDB()
	{





					String sql = "insert into customer values (?,?,?,?,?,?,?,?,?,?,?,?)" ; // Each ? mark corresponds to a  insdex value.
						try{



								// get preparestatemnt
								//Connection cn = cc.getConnection() ;

								PreparedStatement p = cc.getStatement(sql) ;
								//PreparedStatement p = cn.prepareStatement(sql) ;

								p.setInt(1,id );
								p.setString(2,name) ;
								p.setString(3,addr1) ;
								p.setString(4,addr2) ;
								p.setString(5,addr3) ;
								p.setString(6,city) ;
								p.setString(7,state) ;
								p.setString(8,country) ;
								p.setString(9,pincode) ;
								p.setString(10,ph1) ;
								p.setString(11,ph2) ;
								p.setString(12,email) ;


									int x = p.executeUpdate() ;


									if(x > 0)
									 System.out.println("Record Inserted Successfully");
									else
									  System.out.println("Record could not be inserted Successfully");

						//cn.close() ;
						}
						catch(Exception e)
						{
							System.out.println(e.getMessage());

						}


	}





	void updateDetailsInDB( String[] s)//throws Exception

	{

												try{

													id = Integer.parseInt(s[0]) ;
													name = s[1] ;
													addr1 = s[2] ;
													addr2 = s[3] ;
													addr3 = s[4] ;
													city = s[5] ;
													state = s[6] ;
													country = s[7] ;
													pincode = s[8] ;
													ph1 = s[9] ;
													ph2 = s[10] ;
													email = s[11] ;






											String sql = "UPDATE customer SET c_name=?,c_addr1=?,c_addr2=?,c_addr3=?,c_city=?,c_state=?,c_country=?,c_pincode=?,c_ph1=?,c_ph2=?,c_email=? where c_id=?" ;


													//	String sql = "update customer set c_name= ?,c_addr1 = ? where c_id = ?" ;



											// get preparestatemnt

											PreparedStatement p =cc.getStatement(sql) ;
								/*
											p.setInt(3,101);
											p.setString(1,"Rahul") ;
											p.setString(2,"abc") ; */

													p.setInt(12,id );
													p.setString(1,name) ;
													p.setString(2,addr1) ;
													p.setString(3,addr2) ;
													p.setString(4,addr3) ;
													p.setString(5,city) ;
													p.setString(6,state) ;
													p.setString(7,country) ;
													p.setString(8,pincode) ;
													p.setString(9,ph1) ;
													p.setString(10,ph2) ;
													p.setString(11,email) ;


														int x = p.executeUpdate() ;

														if(x > 0)
											 System.out.println("Record Updated Successfully");

								}
								catch(Exception e)
								{

									System.out.println(e.getMessage());
								}

	}





	ResultSet getCustomerDetails() throws Exception// to get all cutomers details.........
	{

					String sql = "select * from customer" ;

					PreparedStatement p = cc.getStatement(sql) ;

					return p.executeQuery() ;

	}




	ResultSet getCustomerDetails(int id) throws Exception // to get details of particular customer....
		{

						String sql = "select * from customer where c_id =?" ;

						PreparedStatement p = cc.getStatement(sql) ;

						p.setInt(1,id);

						return p.executeQuery() ;

	}

}